package zbase;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Calendar;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Vars {

    private static String Version = "База заявок v1.00-00";

    public static String getVersion() {
        return Version;
    }
    // Properties
    /*
     * Username - database user name;
     * Userpass - database user password;
     * DB_URL - url for connecting to database.
     * SortMode
     * GroupMode
     */
    public static Properties prop = new Properties();
    public static String PropFileName = "Options.xml";

    public static void SaveProperties() {
        try {
            prop.storeToXML(new FileOutputStream(PropFileName, false), null);
        } catch (IOException ex) {
            System.out.println("Vars.SaveProperties(): " + ex.toString());
        }
    }

    public static void LoadProperties() {
        try {
            Vars.prop.loadFromXML(new FileInputStream(PropFileName));
        } catch (IOException ex) {
            System.out.println("Vars.LoadProperties(): " + ex.toString());
        }
    }

    public static class obj_User {

        public static String UserName = "";
        public static Boolean Admin = false;
        public static Boolean CanZmain = false;
        public static Boolean CanObjects = false;
        public static Boolean CanServices = false;
    }

    public static String getHexString(String str) {
        String hexstr = "";
        int i = 0;
        while (i < str.length()) {
            Integer ic = str.codePointAt(i);
            hexstr = hexstr + Integer.toHexString(ic);
            hexstr = hexstr + "|";
            i++;
        }
        return hexstr;
    }

    public static String getStringFromHex(String hexstr) {
        if (hexstr == null) {
            return "";
        }
        String str = "";
        String s = "";
        Integer ci = 0;
        char c = (char) 0;
        int i = 0;
        while (i < hexstr.length()) {
            if (!hexstr.substring(i, i + 1).equals("|")) {
                s = s + hexstr.substring(i, i + 1);
                i++;
            } else {
                try {
                    ci = Integer.parseInt(s, 16);
                } catch (NumberFormatException ex) {
                    Logger.getLogger(Vars.class.getName()).log(Level.SEVERE, null, ex);
                    return "Error parsing HEX";
                }
                c = (char) ci.intValue();
                str = str + c;
                s = "";
                i++;
            }
        }
        return str;
    }
    // Raport properties
    public static Boolean r_m = true;
    public static Boolean r_jrb1 = true;
    public static Boolean r_jrb3 = false;
    public static Boolean r_jrb2 = true;
    public static Boolean r_jrb4 = false;
    public static Boolean r_jrb5 = true;
    public static Boolean r_jrb6 = false;
    public static Boolean r_jcb1 = false;
    public static Boolean r_jcb2 = false;
    public static Boolean r_jcb4 = false;
    public static Boolean r_jcb5 = false;
    public static Calendar r_ca1 = null;
    public static Calendar r_ca2 = null;
    public static int r_ok = -1;
    public static int r_sk = -1;
    public static String r_t1 = "";
    public static String r_t2 = "";
}
